/*
 * Created on Mar 9, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.scohen.juploadr.app;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * @author steve
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class ImageTest {
    private static Image fullImage;

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        final ImageData imageData;// = new
                                    // ImageData("C:/temp/Idea_PureWhite.jpg");
        fullImage = new Image(display, ImageTest.class.getClassLoader()
                .getResourceAsStream("org/scohen/juploadr/resources/logo.png"));

        imageData = fullImage.getImageData();

        imageData.alpha = 128;

        Canvas canvas = new Canvas(shell, SWT.NONE);
        canvas.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                String displayText = "transparent label";

                Point stringWidth = e.gc.stringExtent(displayText);
                ImageData labelData = new ImageData(imageData.width,
                        stringWidth.y + 5, 32, new PaletteData(0xFF, 0xFF00,
                                0xFF0000));

                labelData.alpha = 64;
                Image label = new Image(e.display, labelData);
                GC gc = new GC(label);
                gc.setBackground(e.display.getSystemColor(SWT.COLOR_BLUE));
                gc.setForeground(e.display.getSystemColor(SWT.COLOR_WHITE));
                gc.fillRectangle(0, 0, imageData.width, labelData.height);

                gc.drawString(displayText, 5, 0, true);
                labelData = label.getImageData();
                labelData.alpha = 64;
                e.gc.drawImage(fullImage, 0, 0);
                e.gc.drawImage(label, 0, 0);
                gc.dispose();
                label.dispose();

            }
        });
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
}